package com.jade.editor.anisotropy.editors;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.wb.swt.SWTResourceManager;

import com.jade.editor.anisotropy.handler.PathEditorInput;
import com.jade.editor.anisotropy.node.Collector;
import com.jade.editor.anisotropy.parts.DrawArea;
import com.jade.editor.anisotropy.parts.StatusBar;
import com.jade.editor.anisotropy.parts.ToolBarSide;



public class AnisotropyEditor extends EditorPart {
	public AnisotropyEditor() {
	}
	public static final String ID = "com.jade.editor.anisotropy.editors.AnisotropyEditor";
	
	private PathEditorInput _input = null;
	private boolean _dirty = false;
	private DrawArea _drawArea = null;
	private AnisotropyModel _model = null;

	@Override
	public void doSave(IProgressMonitor monitor) {
		Collector c = _drawArea.getCollector();
		
		_model.setSize(_drawArea.getDrawAreaSize());
		_model.setNodeList(c.getNodeList());
		_model.setCortegeList(c.getCortegeList());
		
		_model.save();
		
		setDirty(false);
	}

	@Override
	public void doSaveAs() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
		_input = (PathEditorInput) input;
		setInput(input);
		setSite(site);
		setPartName(input.getName());
		
		_model = new AnisotropyModel(_input.getPath().toString());
		
		// TODO Auto-generated method stub
		
	}
	
	public void setDirty(boolean b){
		_dirty = b;
		firePropertyChange(IEditorPart.PROP_DIRTY);
	}

	@Override
	public boolean isDirty() {
		return _dirty;
	}

	@Override
	public boolean isSaveAsAllowed() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void createPartControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		
		container.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		container.setLayout(null);
		
		_drawArea= new DrawArea(container, _model, this);
		new ToolBarSide(container, _drawArea, _input.getPath(), _model, this);
		new StatusBar(container, _drawArea);
		
		
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}



}
